#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int T,n,m,l,vm,p[N],d[N],v[N],a[N],cnt1,cnt2;
struct node{
    int vi,ai,di;
}record[N];
bool cmp(node x,node y){
    return x.di<y.di;
}
int main(){
   freopen("detect.in","r",stdin);
   freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        cnt1=0;
        scanf("%d%d%d%d",&n,&m,&l,&vm);
        cnt2=m-1;
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
            if(a[i]==0&&v[i]>vm){
                cnt1++;
                record[cnt1].di=d[i];
                record[cnt1].ai=a[i];
                record[cnt1].vi=v[i];
            }
        }
        sort(record+1,record+1+cnt1,cmp);
        for(int i=1;i<=m;i++)scanf("%d",&p[i]);
        if(record[cnt1].di<=p[m]&&cnt1!=0){
            cnt2=m-1;
            goto f;
        }
        else{
            for(int i=cnt1;i>=1;i--){
                if(record[i].di>p[m]) cnt1--;
            }
            if(cnt1==0) cnt2=m;
        }
        f: printf("%d %d\n",cnt1,cnt2);
    }


    return 0;
}


